package com.learn.databinding.workwithobservabledataobjects.bindlayoutwithstateflow

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.exercise.struct.base.BaseDataBindingActivity
import com.learn.databinding.R
import com.learn.databinding.databinding.ActivityBindLayoutWithStateFlowBinding

class BindLayoutWithStateFlowActivity :
    BaseDataBindingActivity<ActivityBindLayoutWithStateFlowBinding>() {
    override val layoutResId: Int
        get() = R.layout.activity_bind_layout_with_state_flow

    private val mViewModel: BindLayoutWithStateFlowViewModel by viewModels()

    override fun setToolbar() {
        mToolbar.setTitle("BindLayoutWithStateFlow")
    }

    override fun initView() {
        //设置DataBinding的lifecycleOwner
        mDataBinding.lifecycleOwner = this
        //绑定ViewModel到Layout
        mDataBinding.viewModel = mViewModel
    }

    companion object {
        fun start(context: Context) {
            Intent(context, BindLayoutWithStateFlowActivity::class.java)
                .also { context.startActivity(it) }
        }
    }
}